package cn.i7baozh.starter.gateway.handler;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

/**
 * 包装返回值
 *
 * @author : baoqi.zhang
 * @date :   2022/5/20 11:30
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class GatewayResult implements Serializable {

    private int code;

    private String message;

    private Object data;

    public static GatewayResult success(Object data) {
        return GatewayResult.builder()
                .code(HttpStatus.OK.value())
                .message(HttpStatus.OK.getReasonPhrase())
                .data(data)
                .build();
    }

    public static GatewayResult error() {
        return GatewayResult.builder()
                .code(HttpStatus.INTERNAL_SERVER_ERROR.value())
                .message(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase())
                .build();
    }

}
